package com.gongj.rabbit.direct;

import com.gongj.rabbit.utils.RabbitMQUtil;
import com.rabbitmq.client.*;

import java.io.IOException;

public class Customer {
    public static void main(String[] args) throws IOException {
        Connection conn = RabbitMQUtil.createConn();

        Channel channel = conn.createChannel();
        //交换机名称
        String exchangeName = "logs_direct";
        //声明direct交换机
        channel.exchangeDeclare(exchangeName,BuiltinExchangeType.DIRECT);
        //创建临时队列
        String queue = channel.queueDeclare().getQueue();
        //绑定队列和交换机
        channel.queueBind(queue,exchangeName,"error");
        channel.queueBind(queue,exchangeName,"info");
        channel.queueBind(queue,exchangeName,"warning");
        //消费消息
        channel.basicConsume(queue,true,new DefaultConsumer(channel){
            @Override
            public void handleDelivery(String consumerTag, Envelope envelope, AMQP.BasicProperties properties, byte[] body) throws IOException {
                System.out.println("消费者-1-error、info、warning级别日志打印：" + new String(body));
            }
        });
    }
}
